/**
 * Created by oiuyt on 2018/7/18.
 */
import React, { Component } from 'react';

import ReactHookRedux from 'react-hooks-redux';
const { Provider, store } = ReactHookRedux({
    isDev: true, // 打印日志
    initialState: { name: 'dog', age: 0 },
});

function actionOfAdd() {
    return {
        type: 'add the count',
        reducer(state) {
            return { ...state, age: state.age + 1 }; // 每次需要返回一个新的 state
        },
    };
}

function Button() {
    function handleAdd() {
        store.dispatch(actionOfAdd()); //dispatch
    }
    return <button onClick={handleAdd}>add</button>;
}

function Page() {
    const state = store.useContext();
    return (
        <div>
            {state.age} <Button />{' '}
        </div>
    );
}

class Test13 extends Component {


    render() {
        return (
            <Provider>
                <Page />
            </Provider>
        );
    }
}


export default Test13
